package com.example.demo.controller;

import com.example.demo.config.Result;
import com.example.demo.dao.CategoryService;
import com.example.demo.entity.Category;
import com.example.demo.mapper.CategoryMapper;

import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.slf4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.List;

/**
 * @Author: lu
 * @Date: 2024-03-11-19:12
 * @Description:
 */
@RestController
@Slf4j
@RequestMapping("/person")
public class CategoryController {

    @Autowired
    CategoryMapper categoryMapper;

    @Autowired
    CategoryService categoryService;

    /*
    查询全部
     */
    @PostMapping("/test")
    @ApiOperation("查询全部")
    public  List<Category> test(){
        List<Category> categories = categoryMapper.selectList(null);
        return  categories;
    }

    /*
    通过id进行查询，id=？
     */
    @PostMapping("/test1")
    public  Category test1(){
        Category category = categoryMapper.selectById(1);
        return  category;
    }

    /*
    通过id进行查询，id in (?,?,?)
     */
    @PostMapping("/test2")
    public List<Category>  test2(){
        List<Category> category = categoryMapper.selectBatchIds(Arrays.asList(1,2,3));
        return  category;
    }

    @GetMapping("/{id}")
    @ApiOperation("通过id进行查询")
    public Result<Category> getById (@PathVariable("id") int id){
        return Result.success(categoryService.getById(id));
    }

    @PostMapping("/delete/{id}")
    @ApiOperation("通过id进行删除")
    public Result<Boolean> deleteById (@PathVariable("id") int id,@RequestBody Category category){
        category.setCategoryId(id);
        category.setIsDelete(1);
        return Result.success(categoryService.updateById(category));
    }





}
